#pragma once

#include "SafeQueue.h"

// 日志宏定义
#define LOG_INFO(log_info_format, ...) \
    do { \
        char log_info[1024] = {0}; \
        snprintf(log_info, 1024, log_info_format, ##__VA_ARGS__); \
        char log_line_info[2048] = {0}; \
        snprintf(log_line_info, 2048, "%s:%s:%d ==> %s", __FILE__, __FUNCTION__, __LINE__, log_info); \
        Logger::GetInstance().Log(INFO, log_line_info); \
    } while(0)

#define LOG_ERROR(log_error_format, ...) \
    do { \
        char log_error[1024] = {0}; \
        snprintf(log_error, 1024, log_error_format, ##__VA_ARGS__); \
        char log_line_error[2048] = {0}; \
        snprintf(log_line_error, 2048, "%s:%s:%d ==> %s", __FILE__, __FUNCTION__, __LINE__, log_error); \
        Logger::GetInstance().Log(ERROR, log_line_error); \
    } while(0)


enum LogLevel
{
    INFO,
    ERROR
};

class Logger
{
public:
    static Logger& GetInstance();

    // 把日志写入m_safe_queue
    void Log(LogLevel log_level, const std::string& message);


private:
    // 把日志写入文件
    Logger();

    Logger(const Logger&) = delete;
    Logger& operator=(const Logger&) = delete;
    Logger(Logger&&) = delete;
    Logger& operator=(Logger&&) = delete;

    SafeQueue<std::string> m_safe_queue;
};

